﻿using EkStudio.com.bean.xml.reflection;
using EkStudio.com.bean.xml.RootInterface;
using System;
using System.Collections.Generic;

namespace EkStudio.com.bean.xml.BillMultiple
{
    public class BillMultipleParamRoot : BillUiFormatContainer
    {

        private int maxid = 0;

        private List<BillMultipleParamItem> paramItem = null;


        [Xml]
        public int Maxid
        {
            get { return maxid; }

            set { maxid = value; }
        }
        [XmlElement]
        public List<BillMultipleParamItem> ParamItem
        {
            get
            {
                return paramItem;
            }

            set
            {
                paramItem = value;
            }
        }
        [XmlTransient]
        public object ParentBean
        {
            get
            {
                return null;
            }

            set
            {
                
            }
        }

        public void addNode(BillUiFormatNode node, BillFormatModule format)
        {
            BillMultipleParamItem it = node as BillMultipleParamItem;
            if (it != null)
            {
                it.LanguageTexts = this.getNLanguageText(format);
                if (paramItem == null) paramItem = new List<BillMultipleParamItem>();
                paramItem.Add(it);
            }
        }

        public void removeNode(BillUiFormatNode node)
        {
            if (this.paramItem != null && paramItem.Count > 0)
            {
                BillMultipleParamItem it = node as BillMultipleParamItem;
                if (it != null && paramItem.Contains(it))
                {
                    paramItem.Remove(it);
                }
            }
        }

        public object Clone()
        {
            throw new NotImplementedException();
        }

        public string getNLanguageText(BillFormatModule format)
        {
            String result = "";
            int tempMaxid = maxid + 1;
            if (format != null)
            {
                string text = format.getLanguageText();
                int index = text.IndexOf("Caption");
                int length = text.Length - 7;
                result = text.Substring(0, length);
                result = result + "Param[" + tempMaxid + "].Caption";
            }
            this.Maxid = tempMaxid;
            return result;
        }

        public void moveDown(BillUiFormatNode node)
        {
            
        }

        public void moveUp(BillUiFormatNode node)
        {
            
        }

        

        public void updateLanguageText(BillFormatModule format)
        {
            this.maxid = 0;
            if (this.paramItem != null && this.paramItem.Count > 0)
            {
                foreach (BillMultipleParamItem group in this.paramItem)
                {
                    group.LanguageTexts = this.getNLanguageText(format);
                }
            }
        }
    }
}
